package com.sunther.document.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sunther.document.dao.TermProjectMidDao;
import com.sunther.document.entity.TermProjectMidEntity;
import com.sunther.document.service.TermProjectMidService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author csb
 * @description: TODO
 * @date 2023/7/10 10:45
 */
@Service
public class TermProjectMidServiceImpl extends ServiceImpl<TermProjectMidDao, TermProjectMidEntity> implements TermProjectMidService {
    @Override
    public Map<String, Set<String>> getProIdsByTermIdsMap(Set<String> ids) {
        Map<String, Set<String>> map = new HashMap<>();
        if(null != ids && ids.size() > 0){
            QueryWrapper<TermProjectMidEntity> wrap = new QueryWrapper<>();
            wrap.in("term_id",ids);
            List<TermProjectMidEntity> list = list(wrap);
            Map<String, List<TermProjectMidEntity>> collect = list.stream().collect(Collectors.groupingBy(TermProjectMidEntity::getTermId));
            collect.forEach((k,v) -> {
                Set<String> set = v.stream().map(TermProjectMidEntity::getProjectId).collect(Collectors.toSet());
                map.put(k,set);
            });
        }
        return map;
    }
}
